@use '../variables';
@use '../mixins';

$time-picker-cell-height: 28px;

@include mixins.b(time-picker) {
  $selector: &;

  position: relative;
  display: inline-flex;
  align-items: center;
  height: var(--size);
  padding: 0 calc(var(--horizontal-space) - 1px);
  font-size: var(--font-size);
  vertical-align: top;
  cursor: pointer;
  background-color: var(--#{variables.$prefix}background-color-input);
  border: 1px solid var(--#{variables.$prefix}color-border);
  border-radius: var(--#{variables.$prefix}border-radius);
  transition: border-color var(--#{variables.$prefix}animation-duration-base) linear;

  &:hover,
  &:focus-within {
    border-color: var(--#{variables.$prefix}color-light-primary);
  }

  @each $invalid, $color in ('warning': 'warning', 'error': 'danger') {
    &[data-l-form-invalid='#{$invalid}'] {
      border-color: var(--#{variables.$prefix}color-#{$color}) !important;

      #{$selector}__input {
        caret-color: var(--#{variables.$prefix}color-#{$color}) !important;
      }

      #{$selector}__indicator {
        background-color: var(--#{variables.$prefix}color-#{$color}) !important;
      }
    }
  }

  @include mixins.when(disabled) {
    color: var(--#{variables.$prefix}color-disabled);
    pointer-events: none;
    background-color: var(--#{variables.$prefix}background-color-disabled);

    @include mixins.e(icon) {
      color: var(--#{variables.$prefix}color-disabled);
    }
  }

  @include mixins.m(small) {
    --size: var(--#{variables.$prefix}select-size, var(--#{variables.$prefix}size-small));
    --horizontal-space: var(--#{variables.$prefix}select-horizontal-space, var(--#{variables.$prefix}horizontal-space-small));
    --font-size: var(--#{variables.$prefix}select-font-size, var(--#{variables.$prefix}font-size-small));
  }

  @include mixins.m(medium) {
    --size: var(--#{variables.$prefix}select-size, var(--#{variables.$prefix}size-medium));
    --horizontal-space: var(--#{variables.$prefix}select-horizontal-space, var(--#{variables.$prefix}horizontal-space-medium));
    --font-size: var(--#{variables.$prefix}select-font-size, var(--#{variables.$prefix}font-size-medium));
  }

  @include mixins.m(large) {
    --size: var(--#{variables.$prefix}select-size, var(--#{variables.$prefix}size-large));
    --horizontal-space: var(--#{variables.$prefix}select-horizontal-space, var(--#{variables.$prefix}horizontal-space-large));
    --font-size: var(--#{variables.$prefix}select-font-size, var(--#{variables.$prefix}font-size-large));
  }

  @include mixins.e(input) {
    display: inline-block;
    flex: 1 0 0;
    min-width: 0;
    padding: 0;
    margin: 0;
    font: inherit;
    color: var(--#{variables.$prefix}color-text);
    letter-spacing: inherit;
    appearance: none;
    caret-color: var(--#{variables.$prefix}color-primary);
    background-color: transparent;
    border: none;
    outline: none;

    &::placeholder {
      color: var(--#{variables.$prefix}color-disabled);
    }

    &:disabled {
      color: var(--#{variables.$prefix}color-disabled);

      &::placeholder {
        opacity: 0.5;
      }
    }
  }

  @include mixins.e(indicator) {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 1;
    width: 0;
    height: 2px;
    pointer-events: none;
    background-color: var(--#{variables.$prefix}color-primary);
    opacity: 0;
    transition:
      opacity var(--#{variables.$prefix}animation-duration-base) linear,
      left var(--#{variables.$prefix}animation-duration-slow) linear,
      width var(--#{variables.$prefix}animation-duration-base) linear;
  }

  @include mixins.e(separator) {
    flex-shrink: 0;
    margin: 0 8px;
    color: var(--#{variables.$prefix}color-icon-decorator);
  }

  @include mixins.e(clear) {
    position: absolute;
    right: calc(var(--horizontal-space) - 1px);
    z-index: 1;
    color: var(--#{variables.$prefix}color-icon-decorator);
    transition: color var(--#{variables.$prefix}animation-duration-base) linear;

    &:hover,
    &:focus {
      color: var(--#{variables.$prefix}color-light-primary);
    }

    &:active {
      color: var(--#{variables.$prefix}color-dark-primary);
    }
  }

  @include mixins.e(icon) {
    flex-shrink: 0;
    margin-left: 4px;
    color: var(--#{variables.$prefix}color-icon-decorator);
  }

  @include mixins.e(panel) {
    display: inline-block;
    vertical-align: top;
  }

  @include mixins.e(header) {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 41px;
    border-bottom: 1px solid var(--#{variables.$prefix}color-divider);
  }

  @include mixins.e(column) {
    position: relative;
    display: inline-block;
    height: calc(8px + #{$time-picker-cell-height} * 8);
    padding: 4px 0;
    margin: 0;
    overflow: hidden auto;
    vertical-align: top;
    list-style: none;

    &::after {
      display: block;
      height: calc(#{$time-picker-cell-height} * 7);
      content: '';
    }
  }

  @include mixins.e(cell) {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: $time-picker-cell-height;
    margin: 0;
    font-variant-numeric: tabular-nums;
    list-style: none;
    cursor: pointer;

    &:not(.is-active):hover {
      background-color: var(--#{variables.$prefix}background-color-hover);
    }

    @include mixins.when(active) {
      background-color: var(--#{variables.$prefix}background-color-primary);
    }

    @include mixins.when(disabled) {
      color: var(--#{variables.$prefix}color-disabled);
      pointer-events: none;
    }
  }

  @include mixins.e(footer) {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 41px;
    border-top: 1px solid var(--#{variables.$prefix}color-divider);
  }
}

@include mixins.b(time-picker-popup) {
  position: fixed;
  background-color: var(--#{variables.$prefix}background-color);
  border-radius: var(--#{variables.$prefix}border-radius);
  box-shadow: var(--#{variables.$prefix}box-shadow-popup);
}
